package io.renren.modules.collecting.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import io.renren.modules.collecting.entity.CollectingDeviceEntity;
import io.renren.modules.collecting.service.CollectingDeviceService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;


/**
 * 采集设备
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2024-06-27 13:12:13
 */
@RestController
@RequestMapping("device")
public class CollectingDeviceController {
    @Autowired
    private CollectingDeviceService collectingDeviceService;

    /**
     * 设备列表
     */
    @RequestMapping("/getList")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = collectingDeviceService.getList(params);
        return R.ok(page);
    }

    /**
     *
     */
    @RequestMapping("getBindList")
    public R getBindList(@RequestBody List<Integer> ids) {
        return R.ok(collectingDeviceService.getBindList(ids));
    }

    /**
     * 设备详情
     */
    @RequestMapping("get")
    public R get(Integer id) {
        CollectingDeviceEntity collectingDevice = collectingDeviceService.getById(id);
        return R.ok(collectingDevice);
    }

    /**
     * 保存设备
     */
    @RequestMapping("add")
    public R add(@RequestBody CollectingDeviceEntity collectingDevice) {
        collectingDevice.setModifyTime(new Date());
        collectingDeviceService.save(collectingDevice);
        return R.ok();
    }

    /**
     * 修改设备
     */
    @RequestMapping("update")
    public R update(@RequestBody CollectingDeviceEntity collectingDevice) {
        collectingDevice.setModifyTime(new Date());
        collectingDeviceService.updateById(collectingDevice);
        return R.ok();
    }

    /**
     * 删除设备
     */
    @RequestMapping("delete")
    public R delete(Integer id) {
        collectingDeviceService.removeById(id);
        return R.ok();
    }

}
